package com.lecyon.farm.util;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;

import java.io.StringWriter;

/**
 * @author Yao Zheng
 * @Date 2020/4/23 15:39
 */
public class WKTUtil {

    /**
     * 由wkt格式的geometry生成geojson
     *
     * @param wkt
     * @return
     */
    public static String wktToJson(String wkt) {
        String json = null;
        try {
            WKTReader reader = new WKTReader();
            Geometry geometry = reader.read(wkt);
            StringWriter writer = new StringWriter();
//            GeometryJSON g = new GeometryJSON(20);
//            g.write(geometry, writer);
            json = writer.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

}
